<include file="Public/header"/>

<div id="app">
    <!-- sidebar -->
    <include file="Public/left"/>
    <!-- / sidebar -->
    <div class="app-content">
        <!-- start: TOP NAVBAR -->
        <include file="Public/headernav"/>
        <!-- end: TOP NAVBAR -->
        <div class="main-content">
            <div class="wrap-content container" id="container">
                <!-- start: PAGE TITLE -->
                <section id="page-title">
                    <div class="row">
                        <div class="col-sm-8">
                            <h1 class="mainTitle">{$msgtitle}</h1>
                            <span class="mainDescription">商品信息</span>
                        </div>
                    </div>
                </section>
                <!-- end: PAGE TITLE -->
                <!-- start: YOUR CONTENT HERE -->
                <div class="container-fluid container-fullw bg-white">
                    <form action="" role="form" id="form2" novalidate="novalidate" method="post">
                        <input type="hidden" name="id" value="{$data[id]}" />
                        <div class="row">
                            <div class="col-md-12">
                                <div class="tabbable">
                                    <ul class="nav nav-tabs tab-padding tab-space-3 tab-blue" id="myTab4">
                                        <li class="active">
                                            <a data-toggle="tab" href="#business_overview">
                                                业务基本信息
                                            </a>
                                        </li>
                                        <li>
                                            <a data-toggle="tab" href="#price_info">
                                                资费信息
                                            </a>
                                        </li>
                                        <li>
                                            <a data-toggle="tab" href="#warm_prompt ">
                                                温馨提示
                                            </a>
                                        </li>
                                    </ul>
                                    <div class="tab-content">
                                        <div id="business_overview" class="tab-pane fade  in active">
                                            <div class="row">
                                                <div class="col-md-8">
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            业务分类
                                                            <span class="symbol required"  aria-required="true"></span>
                                                        </label>
                                                        <select class="form-control" id="business_type_id" name="business_type_id">
                                                            <option value="">请选择</option>
                                                            <volist name="businessType" id="vo">
                                                                <option value="{$vo.id}"
                                                                <if condition="$data.id and $data['business_type_id'] eq $vo.id ">
                                                                    selected="selected"
                                                                </if>
                                                                >
                                                                {$vo.name}
                                                                </option>
                                                            </volist>

                                                        </select>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            业务名称 <span class="symbol required"
                                                                       aria-required="true"></span>
                                                        </label>
                                                        <input type="text" name="business_name" value="{$data.business_name}"
                                                               id="business_name" placeholder="业务名称" class="form-control">
                                                    </div>

                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            业务描述<span class="symbol " ></span>
                                                        </label>
                                                        <textarea id="business_desc" name="content" class=" autosize"
                                                                  data-autosize-on="true"
                                                                  style="overflow: hidden; resize: horizontal; word-wrap: break-word;  width: 100%;  height: 100px;">{$data.content}</textarea>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            状态
                                                        </label>
                                                        <div class="clip-radio radio-primary fa-hover Primary">
                                                            <input type="radio" value="1" name="is_on_sale"
                                                                   id="id_no"
                                                            <if condition="$data.id and $data.is_on_sale eq 0">
                                                                <else/>
                                                                checked="checked"
                                                            </if>
                                                            >
                                                            <label for="id_no">
                                                                上架
                                                            </label>


                                                            <input type="radio" value="0" name="is_on_sale"
                                                                   id="id_yes"
                                                            <if condition="$data.id and $data.is_on_sale eq 0">
                                                                checked="checked"
                                                            </if>
                                                            >
                                                            <label for="id_yes">
                                                                下架
                                                            </label>
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            是否在首页显示
                                                        </label>

                                                        <div class="clip-radio radio-primary fa-hover Primary">
                                                            <input type="radio" value="1" name="is_show_index"
                                                                   id="is_show_index_yes"
                                                                <if condition="$data.id and $data.is_show_index eq 1">
                                                                    checked="checked"
                                                                </if>
                                                            />
                                                            <label for="is_show_index_yes">
                                                                是
                                                            </label>
                                                            <input type="radio" value="0" name="is_show_index"
                                                                   id="is_show_index_no"
                                                                <if condition="$data.id and $data.is_show_index eq 0">
                                                                    checked="checked"
                                                                </if>
                                                            />
                                                            <label for="is_show_index_no">
                                                                否
                                                            </label>
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            商品排序<span class="symbol required"
                                                                      aria-required="true"></span>
                                                        </label>
                                                        <input type="text" name="sort"
                                                               value="{$data.sort|default='0'}"
                                                               id="business_sort" placeholder="商品排序"
                                                               class="form-control">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div id="price_info" class="tab-pane fade">
                                            <div class="row">
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <span class="control-label">
                                                            是否含子业务
                                                        </span>
                                                        <div class="clip-radio radio-primary fa-hover Primary">
                                                            <input type="radio" value="1" name="has_child"
                                                                   id="has_child_yes"
                                                                <if condition="$data.id and $data.has_child eq 1">
                                                                    checked="checked"
                                                                </if>
                                                            />
                                                            <label for="has_child_yes">
                                                                是
                                                            </label>
                                                            <input type="radio" value="0" name="has_child" id="has_child_no"
                                                                <if condition="$data.id and $data.has_child eq 0">
                                                                    checked="checked"
                                                                </if>
                                                            />
                                                            <label for="has_child_no">
                                                                否
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="form-group" id="business_price_form_group"
                                                        <if condition="$data['id'] and $data['has_child'] eq 0" >
                                                            <else/>
                                                            style="display: none"
                                                        </if>
                                                    >
                                                        <label class="control-label">
                                                            业务价格<span class="symbol required"
                                                                      aria-required="true"></span>
                                                        </label>

                                                        <div class="input-group">
                                                            <span class="input-group-addon">￥</span>
                                                            <input type="text" name="price"
                                                                   value="{$data.price|default='0'}"
                                                                   id="business_price" placeholder="业务价格"
                                                                   class="form-control">
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="row">
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            套餐内资费信息
                                                        </label>
                                                        <div >
                                                            <table class="table table-hover" id="inside_info_table">
                                                                <thead>
                                                                <tr>
                                                                    <td class="center">
                                                                        <button class="btn btn-primary btn-xs add_info_table" data-name="inside_info[]" type="button">
                                                                           新增 <i class="glyphicon glyphicon-plus"></i>
                                                                        </button>
                                                                    </td>
                                                                    <td></td>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                    <tr >
                                                                        <td class="center">
                                                                            <input type="text" name="inside_info[]" value="{$data.inside_info[]}"
                                                                                   placeholder="套餐内资费权益" class="form-control">
                                                                        </td>
                                                                        <td></td>
                                                                    </tr>
                                                                    <tr >
                                                                        <td class="center">
                                                                            <input type="text" name="inside_info[]" value="{$data.inside_info[]}"
                                                                                   placeholder="套餐内资费权益" class="form-control">
                                                                        </td>
                                                                        <td>
                                                                            <a class="btn btn-transparent btn-xs delete-info-item"  tooltip="Edit"  tooltip-placement="top"
                                                                            data-toggle="tooltip"data-original-title="删除">
                                                                            <i class="glyphicon glyphicon-remove"></i>
                                                                            </a>
                                                                        </td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-lg-offset-1 col-md-3">
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            套餐外资费信息
                                                        </label>

                                                        <div >
                                                            <table class="table table-hover" id="outside_info_table">
                                                                <thead>
                                                                <tr>
                                                                    <td class="center">
                                                                        <button class="btn btn-primary btn-xs add_info_table" data-name="outside_info[]" type="button">
                                                                            新增 <i class="glyphicon glyphicon-plus"></i>
                                                                        </button>
                                                                    </td>
                                                                    <td></td>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                <tr >
                                                                    <td class="center">
                                                                        <input type="text" name="outside_info[]" value="{$data.outside_info[]}"
                                                                               placeholder="套餐外资费权益" class="form-control">
                                                                    </td>
                                                                    <td></td>
                                                                </tr>
                                                                <tr >
                                                                    <td class="center">
                                                                        <input type="text" name="outside_info[]" value="{$data.outside_info[]}"
                                                                               placeholder="套餐外资费权益" class="form-control">
                                                                    </td>
                                                                    <td>
                                                                        <a class="btn btn-transparent btn-xs delete-info-item"  tooltip="Edit"  tooltip-placement="top"
                                                                           data-toggle="tooltip"
                                                                           data-original-title="删除"><i class="glyphicon glyphicon-remove"></i></a>
                                                                    </td>
                                                                </tr>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <br/>
                                            <div class="row" id="child_table_list"
                                                <if condition="$data['id'] and $data['has_child'] eq 1">
                                                    <else />
                                                    style="display: none"
                                                </if>
                                            >
                                                <div class="col-md-8">
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                           子业务：                                                                    <th class="center" style="padding: 0">
                                                            <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#exampleModal">
                                                                新增子业务
                                                            </button>
                                                        </label>
                                                        <div >
                                                            <table id="child_business_list" class="table table-hover" >
                                                                <thead>
                                                                <tr>
                                                                    </th>
                                                                    <th class="center">业务名称</th>
                                                                    <th class="hidden-xs">业务价格</th>
                                                                    <th class="center">上/下架</th>
                                                                    <th class="center">操作</th>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                <volist  name="childrenList['list']" id='vo' key='key'>
                                                                    <tr  >
                                                                        <td class="center">
                                                                            {$vo.business_name}
                                                                        </td>
                                                                        <td class="hidden-xs">{$vo.price}</td>
                                                                        <td id="is_sale{$vo.id}" class="center"><if condition="$vo.is_on_sale eq 1">
                                                                            <a href="javascript:void(0)"
                                                                               class="btn btn-transparent btn-xs"  tooltip="Edit"  tooltip-placement="top"
                                                                               data-toggle="tooltip" onclick="changeStatus({$vo.id},{$vo.is_on_sale})"
                                                                               data-original-title="下架"><i class="fa fa-check-circle" ></i></a>
                                                                            <else/>
                                                                            <a href="javascript:void(0)"
                                                                               class="btn btn-transparent btn-xs"  tooltip="Edit"  tooltip-placement="top"
                                                                               data-toggle="tooltip" onclick="changeStatus({$vo.id},{$vo.is_on_sale})"
                                                                               data-original-title="上架"><i class="fa fa-check-circle" style="color:#ccc;"  value="1"></i></a>
                                                                        </if>
                                                                        </td>
                                                                        <td class="center">
                                                                            <div class="visible-md visible-lg hidden-sm hidden-xs">
                                                                                <a href="{:U("Admin/business/business_edit",array('id'=>$vo['id']))}"
                                                                                class="btn btn-transparent btn-xs"  tooltip="Edit"  tooltip-placement="top"
                                                                                data-toggle="tooltip" data-original-title="编辑">
                                                                                <i class="fa fa-pencil"></i></a>

                                                                                <a href="{:U("Admin/Goods/Goods_del",array('id'=>$vo['id']))}"
                                                                                class="btn btn-transparent btn-xs"  tooltip="Edit"  tooltip-placement="top"
                                                                                data-toggle="tooltip" onclick="return confirm('确取删除该商品？')"
                                                                                data-original-title="删除"><i class="fa fa-trash-o"></i></a>
                                                                            </div>
                                                                        </td>
                                                                    </tr>

                                                                </volist>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div id="warm_prompt" class="tab-pane fade">
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label class="control-label">
                                                            温馨提示(业务说明)
                                                        </label>

                                                        <div >
                                                            <table class="table table-hover" id="explain_info_table">
                                                                <thead>
                                                                <tr>
                                                                    <td class="center">
                                                                        <button class="btn btn-primary btn-xs add_info_table" type="button" data-name="explain[]" type="button">
                                                                            新增 <i class="glyphicon glyphicon-plus"></i>
                                                                        </button>
                                                                    </td>
                                                                    <td></td>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                <tr >
                                                                    <td class="center">
                                                                        <input type="text" name="explain[]" value="{$data.explain[]}"
                                                                               placeholder="温馨提示" class="form-control">
                                                                    </td>
                                                                    <td></td>
                                                                </tr>
                                                                <tr >
                                                                    <td class="center">
                                                                        <input type="text" name="explain[]" value="{$data.explain[]}"
                                                                               placeholder="温馨提示" class="form-control">
                                                                    </td>
                                                                    <td >
                                                                        <a class="btn btn-transparent btn-xs delete-info-item"  tooltip="Edit"  tooltip-placement="top"
                                                                           data-toggle="tooltip"
                                                                           data-original-title="删除"><i class="glyphicon glyphicon-remove"></i></a>
                                                                    </td>
                                                                </tr>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                            </div>

                            <div class="col-md-4">
                                <input type="hidden" value="{$data.id}" name="id">
                                <button class="btn btn-primary btn-wide pull-left" type="submit">
                                    提交 <i class="fa fa-arrow-circle-right"></i>
                                </button>
                            </div>

                            <div class="col-md-8">
                                <p>

                                </p>
                            </div>
                        </div>
                    </form>
                </div>
                    <!--start 弹框编辑子业务-->
                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="exampleModalLabel">编辑子业务</h5>
                                <button type="button" class="close" style="margin-top: -20px" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body" style="padding: 15px 30px">
                                <form id="child_info_form" role="form" novalidate="novalidate" method="post">
                                    <input name="child_id" type="hidden" value="" >
                                    <div class="form-group">
                                        <label for="child_business_name" class="col-form-label">
                                            子业务名称<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <input type="text" class="form-control" id="child_business_name" name="child_business_name">
                                    </div>
                                    <div class="form-group">
                                        <label class="col-form-label" for="child_price">
                                            子业务价格<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="input-group">
                                            <span class="input-group-addon">￥</span>
                                            <input type="text" name="child_price" id="child_price"
                                                   value=""
                                                   placeholder="业务价格"
                                                   class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label">
                                            状态
                                        </label>
                                        <div class="clip-radio radio-primary fa-hover Primary">
                                            <input type="radio" value="1" checked name="child_is_on_sale" id="child_id_no" >
                                            <label for="child_id_no">
                                                上架
                                            </label>
                                            <input type="radio" value="0" name="child_is_on_sale" id="child_id_yes" >
                                            <label for="child_id_yes">
                                                下架
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label">
                                            业务排序<span class="symbol required"
                                                      aria-required="true"></span>
                                        </label>
                                        <input type="text" name="child_sort"
                                               value="0"
                                               placeholder="排序(越小越靠前)"
                                               class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label" for="child_info_table">
                                            子业务套餐内资费信息
                                        </label>
                                        <div >
                                            <table class="table table-hover" id="child_info_table">
                                                <thead>
                                                <tr>
                                                    <td class="center">
                                                        <button class="btn btn-primary btn-xs add_info_table" data-name="child_info[]" type="button">
                                                            新增 <i class="glyphicon glyphicon-plus"></i>
                                                        </button>
                                                    </td>
                                                    <td></td>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr >
                                                    <td class="center">
                                                        <input type="text" name="child_info[]" value=""
                                                               placeholder="套餐内资费权益" class="form-control">
                                                    </td>
                                                    <td>
                                                        <a class="btn btn-transparent btn-xs delete-info-item"  tooltip="Edit"  tooltip-placement="top"
                                                           data-toggle="tooltip"data-original-title="删除">
                                                            <i class="glyphicon glyphicon-remove"></i>
                                                        </a>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                                <button id="child_info_form_submit" class="btn btn-primary">确定</button>
                            </div>
                        </div>
                    </div>
                </div>
                    <!--end 弹框编辑子业务-->

                <!-- end: YOUR CONTENT HERE -->
            </div>
        </div>
    </div>
    <!--  FOOTER and SETTINGS -->

    <include file="Public/footer"/>
    <!-- end: FOOTER -->
    <!-- start: OFF-SIDEBAR -->

    <!-- end: OFF-SIDEBAR -->

</div>
<!-- start: MAIN JAVASCRIPTS -->

<include file="Public/javascript"/>

<!-- end: CLIP-TWO JAVASCRIPTS -->

<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
<script src="__PUBLIC__/bootstrap/vendor/ckeditor/ckeditor.js"></script>
<script src="__PUBLIC__/bootstrap/vendor/ckeditor/adapters/jquery.js"></script>
<script src="__PUBLIC__/bootstrap/vendor/jquery-validation/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/jquery.form.js"></script>
<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
<!-- start: CLIP-TWO JAVASCRIPTS -->
<!-- <script src="__PUBLIC__/bootstrap/assets/js/main.js"></script> -->
<!-- start: JavaScript Event Handlers for this page -->
<!--<script src="__PUBLIC__/bootstrap/assets/js/form-validation.js"></script>-->

<script src="__PUBLIC__/bootstrap/vendor/artDialog/artDialog.source.js?skin=default"></script>
<script src="__PUBLIC__/bootstrap/vendor/artDialog/plugins/iframeTools.source.js"></script>

<script src="__PUBLIC__/bootstrap/vendor/ajaxfileupload/ajaxfileupload.js"></script>
<!-- 配置文件 -->
<!--<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>-->
<!--&lt;!&ndash; 编辑器源码文件 &ndash;&gt;-->
<!--<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>-->
<!-- 实例化编辑器 -->

<script src="__PUBLIC__/js/common.js"></script>
<include file="Public/javascript_datepicker"/>
<script>
    var insideInfo = {}
    var outsideInfo = {}
    var explain = {}

    <if condition="$data.id">
        insideInfo = {$data['inside_info']};
        outsideInfo = {$data['outside_info']};
        explain = {$data['explain']};
    </if>
    // onclick="return confirm('确取删除该信息？')"


    // 上下架业务
    function changeStatus(id,value){
        if(value==0){
            value =1;
            var sale='上架';
        }else{
            value=0;
            var sale='下架';
        }
        if(confirm('确定'+sale+'?')){
            $.ajax({
                url:'{:U("Admin/business/is_on_sale")}',
                type:'get',
                data:'id='+id+'&value='+value,
                dataType:'json',
                success:function(data){
                    console.log(value, 'value')
                    if(data.code == 200){
                        $('#is_sale'+id).empty();

                        if(value){
                            var content = '<a href="javascript:void(0)" class="btn btn-transparent btn-xs" tooltip = "Edit" tooltip - placement = "top" data - toggle = "tooltip" onclick = "changeStatus('+id+','+value+')" data - original - title = "'+sale+'" > <i class="fa fa-check-circle" ></i></a>'
                        }else{
                            var content = '<a href="javascript:void(0)" class="btn btn-transparent btn-xs" tooltip = "Edit" tooltip - placement = "top" data - toggle = "tooltip" onclick = "changeStatus('+id+','+value+')" data - original - title = "'+sale+'" > <i class="fa fa-check-circle" style="color:#ccc;"  value="1"></i></a>'
                        }
                        $('#is_sale'+id).append(content);
                        layer.msg(sale+'成功',{icon:6});
                    }else{
                        layer.msg(data.error,{icon:5});
                    }
                }
            })
        }
    }
    $(function () {
        initPage()

        // 初始化页面
        function initPage() {
            setTimeout(function () {
                events() //
                if ($("input[name='id']").val()) {
                    loadTableInfo()
                    loadChilList()
                }
            }, 100)
        }

        // 绑定事件
        function events() {
            // 点击新增资费信息
            $(document).on('click', ".add_info_table", function () {
                const _this = $(this)
                const name = _this.data('name')
                addInfoTable(name)
            })
            //  选择是否有子资费信息
            $(document).on('change', "input[name='has_child']", function () {
                const value = $(this).val()
                if (value == '1') {
                    $('#business_price_form_group').hide()
                    if ($("input[name='id']").val()) {
                        $('#child_table_list').show();
                    }
                } else {
                    $('#business_price_form_group').show()
                    $('#child_table_list').hide();
                }
            })
            // 删除条目
            $(document).on('click', ".delete-info-item", function () {
                const _this = $(this)
                deleteInfoItem(_this)
            })
            // 删除子业务
            $(document).on('click', ".deltete_child", function () {
                if (!confirm('确取删除该信息？')) { return }
                const id = $(this).data('id');
                deletChildBusiness(id)
            })

            // 点击子业务编辑按钮
            $(document).on('click', ".edit_child", function () {
                const id = $(this).data('id');
                getChidlBusinessInfo(id)
            })
            // 业务表单提交及验证的绑定
            formValidateBinde()

            // modal 中子业务表单的提交事件
            childFormValidateBinde()
            $(document).on('click', '#child_info_form_submit', function () {
                $('#child_info_form').submit()
            })
            // modal 隐藏事件
            $('#exampleModal').on('hidden.bs.modal', function () {
                $('#child_info_form')[0].reset()
                $('#child_info_table').find('tbody').html('')
                addInfoTable('child_info[]')
            })
        }
        // 新增资费信息
        function addInfoTable(name, vlaue='') {
            let placeholder = ''
            let tableEle = ''
            if (name.includes('inside')) {
                placeholder = '套餐内资费权益'
                tableEle = '#inside_info_table'
            } else if (name.includes('outside')){
                placeholder = '套餐外资费权益'
                tableEle = '#outside_info_table'
            } else if (name.includes('child')){
                placeholder = '子业务套餐内资权益'
                tableEle = '#child_info_table'
            } else {
                placeholder = '温馨提示'
                tableEle = '#explain_info_table'
            }

            const info_temp =
                `<tr >
                    <td class="center">
                       <input type="text" name="${name}" value="${vlaue}" placeholder="${placeholder}" class="form-control">
                    </td>
                    <td>
                        <a class="btn btn-transparent btn-xs delete-info-item"  tooltip="Edit"  tooltip-placement="top"
                            data-toggle="tooltip" data-original-title="删除">
                            <i class="glyphicon glyphicon-remove"></i>
                        </a>
                    </td>
                 </tr>`;
            $(tableEle).find('tbody').append(info_temp)
        }
        function deleteInfoItem(e) {
            confirm('确取删除该信息？') && e.parent().parent().remove()
        }
        
        // 加载 资费信息
        function loadTableInfo() {
            // var insideInfo = {}
            // var outsideInfo = {}
            // var explain = {}
            if (Object.keys(insideInfo).length) {
                $('#inside_info_table').find('tbody').html('')
                for (let item of Object.keys(insideInfo)) {
                    addInfoTable('inside_info[]', insideInfo[item])
                }
            }
            if (Object.keys(outsideInfo).length) {
                $('#outside_info_table').find('tbody').html('')
                for (let item of Object.keys(outsideInfo)) {
                    addInfoTable('outside_info[]', outsideInfo[item])
                }
            }
            if (Object.keys(explain).length) {
                $('#explain_info_table').find('tbody').html('')
                for (let item of Object.keys(explain)) {
                    addInfoTable('explain[]', explain[item])
                }
            }
        }
        // 提醒添加子业务
        function alertAddChild () {
            $('#myTab4 a[href="#price_info"]').tab('show');
            $('#child_table_form').show();
        }
        // 表单验证绑定
        function formValidateBinde () {
            $("#form2").validate({
                rules: {
                    business_type_id: "required",
                    business_name: "required",
                    content: "required",
                },
                messages: {
                    business_type_id: "请选择业务分类",
                    business_name: "请填写业务名称",
                    content: "填写业务内容",
                },
                focusInvalid:false,
                success: function(label) {
                },
                /*执行ajaxsubmit  */
                submitHandler: function(editform) {
                    var options = {
                        url :  "<?php echo U('admin/business/business_edit' ); ?>",
                        type : "post" ,
                        dataType:'json',
                        target : "#loader",
                        error: function(){layer.msg("服务器没有返回数据，可能服务器忙，请重试",{icon:5});},
                        onwait : "正在处理信息，请稍候...",
                        success: function(response){
                            if(response.code == 200){
                                if ($("input[name='has_child']").val() == 1 && !$("input[name='id']").val()) {
                                    alertAddChild()
                                    layer.msg(`${response.msg},请添加子业务`,{icon:6});
                                    $("input[name='id']").val(response.data.id)
                                } else {
                                    layer.msg(response.msg,{icon:6});
                                    setTimeout(function () {
                                        window.location.href="<?php echo U('admin/business/index'); ?>";
                                    }, 1000);
                                }
                            }else{
                                layer.msg(response.error,{icon:5});
                            }
                        }
                    };
                    setTimeout((function(opt){
                        return function(){
                            $('#form2').ajaxSubmit(opt);
                        }
                    })(options), 300);
                    return false;
                }
            });
        }
        // 子业务 表单验证绑定
        function childFormValidateBinde () {
            $("#child_info_form").validate({
                rules: {
                    child_business_name: "required",
                    child_price: "required",
                },
                messages: {
                    child_business_name: "请填写子业务名称",
                    child_price: "填写业务价格",
                },
                focusInvalid:false,
                success: function(label) {
                },
                /*执行ajaxsubmit  */
                submitHandler: function(editform) {
                    const pid = $("input[name='id']").val();
                    var options = {
                        url : `<?php echo U('admin/business/child_business_edit'); ?>?pid=${pid}`,
                        type : "post" ,
                        dataType:'json',
                        target : "#loader",
                        error: function(){layer.msg("服务器没有返回数据，可能服务器忙，请重试",{icon:5});},
                        onwait : "正在处理信息，请稍候...",
                        success: function(response){
                            if(response.code == 200){
                                loadChilList()
                                $('#exampleModal').modal('hide');
                                layer.msg(response.msg,{icon:6});
                            }
                        }
                    };
                    setTimeout((function(opt){
                        return function(){
                            $('#child_info_form').ajaxSubmit(opt);
                        }
                    })(options), 300);
                    return false;
                }
            });
        }

        // 删除子业务
        function deletChildBusiness(id) {
            const option = {
                url: "<?php echo U('admin/business/childBusinessDel'); ?>",
                dataType: 'json',
                type: 'post',
                data: {id: id},
                success: function (response) {
                    console.log(response)
                    if (response.code == 200) {
                        loadChilList()
                    }
                    layer.msg(response.msg)
                }
            }
            $.ajax(option)
        }

        // 获取某子业务的信息并加载进弹框
        function getChidlBusinessInfo (id) {
            const option = {
                url: "<?php echo U('admin/business/getChildInfo'); ?>",
                dataType: 'json',
                type: 'post',
                data: {id: id},
                success: function (response) {
                    console.log(response)
                    // layer.msg(response.msg)
                    const data = response.data
                    // child_business_name child_price child_is_on_sale child_sort
                    $('input[name="child_id"]').val(data.id)
                    $('input[name="child_business_name"]').val(data.business_name)
                    $('input[name="child_price"]').val(data.price)
                    $(":radio[name='child_is_on_sale'][value='" + data.is_on_sale + "']").prop("checked", "checked")
                    $('input[name="child_sort"]').val(data.sort)
                    const inside_info = data.inside_info ? JSON.parse(data.inside_info) : []
                    if (inside_info && Object.keys(inside_info).length) {
                        $('#child_info_table').find('tbody').html('')
                        for (let item of inside_info) {
                            addInfoTable('child_info[]', item)
                        }
                    }
                    $('#exampleModal').modal('show')
                }
            }
            $.ajax(option)
        }

        // 加载子业务列表
        function loadChilList () {
            const pid = $("input[name='id']").val();
            $.ajax({
                url: "<?php echo U('admin/business/getChildList'); ?>",
                dataType: 'json',
                type    : 'post',
                data    : { pid: pid },
                success: function (response) {
                    console.log(response)
                    const data = response.data;
                    const tableList = data.map(item => (
                        `
                    <tr  >
                        <td class="center">
                            ${item.business_name}
                        </td>
                        <td class="hidden-xs">${item.price}</td>
                         <td id="is_sale${item.id}" class="center">
                            <a href="javascript:void(0)"
                               class="btn btn-transparent btn-xs"  tooltip="Edit"  tooltip-placement="top"
                               data-toggle="tooltip" onclick="changeStatus(${item.id},${item.is_on_sale})"
                               data-original-title="下架"><i class="fa fa-check-circle" style="${item.is_on_sale == 1 ? '' : 'color:#ccc;' }"></i></a>
                        </td>
                        <td class="center">
                            <div class="visible-md visible-lg hidden-sm hidden-xs">
                                <a href="javascript:void(0)" data-id="${item.id}"
                                class="btn btn-transparent btn-xs edit_child"  tooltip="Edit"  tooltip-placement="top"
                                data-toggle="tooltip" data-original-title="编辑">
                                <i class="fa fa-pencil"></i></a>
                                <a href="javascript:void(0)" data-id="${item.id}"
                                class="btn btn-transparent btn-xs deltete_child"  tooltip="Edit"  tooltip-placement="top"
                                data-toggle="tooltip"
                                data-original-title="删除"><i class="fa fa-trash-o"></i></a>
                            </div>
                        </td>
                    </tr>
                    `
                    ))
                    $("#child_business_list").find('tbody').html(tableList)
                }
            })
        }

    })
</script>
<!-- end: JavaScript Event Handlers for this page -->
</body>
</html>
